package edu.udo.sopra10.chaturaji.entities.terminationconditions;

import edu.udo.sopra10.chaturaji.entities.Game;

/**
 * Checks if a {@link Game} has terminated. This is a strategy associated with
 * the game.
 * 
 * @author Simon Dierl
 */
public abstract class TerminationCondition {

	/**
	 * The game controlled by the condition.
	 */
	protected Game game;

	/**
	 * Create a new termination condition for the specified game.
	 * 
	 * @param game
	 *            the terminated game, may be {@code null} if not created.
	 */
	protected TerminationCondition(final Game game) {
		setGame(game);
	}

	@Override
	public boolean equals(final Object obj) {
		return (obj != null) && (obj.getClass() == getClass());
	}

	/**
	 * Get the game terminated by this condition.
	 * 
	 * @return the terminated game, may be {@code null} if not created.
	 */
	public Game getGame() {
		return game;
	}

	@Override
	public int hashCode() {
		return getClass().hashCode();
	}

	/**
	 * Check if the game is terminated under this condition.
	 * 
	 * @return if the game is terminated.
	 */
	public abstract boolean isGameTerminated();

	/**
	 * Set the game terminated by this condition.
	 * 
	 * @param game
	 *            the new terminated game, may be {@code null} if not created.
	 */
	public void setGame(final Game game) {
		this.game = game;
	}

	@Override
	public String toString() {
		return getClass().getSimpleName();
	}
}
